<?php
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') 
{
	if(isset($_POST['coffee_clicks']))
	{
		require_once 'config.php';
		require_once 'functions.php';
		$con = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
		if (mysqli_connect_errno()) {
			echo "Failed to connect to MySQL: " . mysqli_connect_error();
		}
		else
		{	
			mysqli_query($con,"UPDATE coffee_clicks SET clicks = clicks + 1");
			//exit();
			$total = get_clicks();
			$click_per_unit = TOTAL_CLICK/CUP_HEIGHT;
			$cup_fill = $total/$click_per_unit;
			if($cup_fill > CUP_HEIGHT) $cup_fill = CUP_HEIGHT;
			echo $cup_fill . '-'.$total;
			
			mysqli_close($con);
			
		}
		exit;
	} else if($_POST['coffee_init'])
	{

		require_once 'config.php';
		require_once 'functions.php';
		$con = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
		if (mysqli_connect_errno()) {
			echo "Failed to connect to MySQL: " . mysqli_connect_error();
		}
		else
		{	
			$total = get_clicks();
			$click_per_unit = TOTAL_CLICK/CUP_HEIGHT;
			$cup_fill = $total/$click_per_unit;
			if($cup_fill > CUP_HEIGHT) $cup_fill = CUP_HEIGHT;
			echo $cup_fill . '-'.$total;
			mysqli_close($con);
		}
		exit;
	}
}

?>

